package com.chianghao.rock.system.service.dictionary;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chianghao.core.exception.HaoException;
import com.chianghao.core.frame.service.BaseService;
import com.chianghao.rock.system.dao.dictionary.DictionaryMapper;
import com.chianghao.rock.system.dao.dictionary_value.DictionaryValueMapper;
import com.chianghao.rock.system.entity.Dictionary;
import com.chianghao.rock.system.entity.DictionaryValue;

@Service
public class DictionaryService extends BaseService<DictionaryMapper, Dictionary> {

	
	@Autowired
	DictionaryValueMapper dictionaryValueMapper;
	
	
	public void doCreate(Dictionary dictionary) {
		int count = this.queryCount(Dictionary::getCode, dictionary.getCode());
		if(count>0) {
			throw new HaoException("error:code,not.repeatable");
		}
		this.mapper.insert(dictionary);
	}

	public void doDelete(String code) {
		this.deleteByCode(code);
		DictionaryValue where  = new DictionaryValue();
		where.setDictionaryCode(code);
		dictionaryValueMapper.deleteByEntity(where);
	}

	

	


}